package com.aliyun.messagemgt.excel;


import com.alibaba.excel.EasyExcel;

import java.io.InputStream;
import java.util.List;

/**
 * Excel读取工具类
 * @param <T>
 */
public class ExcelReaderUtil<T> {
    private Class<T> clazz;

    public ExcelReaderUtil(Class<T> clazz) {
        this.clazz = clazz;
    }

    public List<T> readByStream(InputStream inputStream) {
        ExcelListener<T> readerListener = new ExcelListener<>();
        EasyExcel.read(inputStream, clazz, readerListener).sheet().doRead();
        return readerListener.getList();
    }

    public List<T> readByPath(String fileName) {
        ExcelListener<T> readerListener = new ExcelListener<>();
        EasyExcel.read(fileName, clazz, readerListener).sheet().doRead();
        return readerListener.getList();
    }

}
